package com.aboo.user.service;

import com.aboo.frame.util.okhttp.OkhttpUtil;
import com.aboo.user.entity.vo.UserVO;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserService {

    public UserVO addUser(UserVO user) {
        String url = "http://127.0.0.1:12805/api/one/user/add";
        Map<String, String> param = new HashMap<>(16);
        param.put("name", user.getName());
        param.put("age", user.getAge());
        String httpBody = OkhttpUtil.doPostJson(url, JSONObject.toJSONString(param));
        JSONObject jo = JSONObject.parseObject(httpBody);

        UserVO result = new UserVO();
        JSONObject data = jo.getJSONObject("data");
        if (data != null) {
            result.setName(data.getString("name"));
            result.setAge(data.getString("age"));
            result.setCard(data.getString("id"));
        }

        return result;
    }

}
